#ifndef INSTRUCTIONSSERVICE_H
#define INSTRUCTIONSSERVICE_H

#include <QObject>
#include <QCoreApplication>
#include "socketclient.h"
#include<QString>
#include<Convertion.h>
#include <sys/stat.h>
#include<SqliteDriver.h>
#include <QHostAddress>
#include "XmlParser.h"


struct YingGuang{
    QString stage;  //阶段
    QString number; //编号
    QString step;   //步骤
    QString cycle_number;   //循环数
    QList<QHash<QString,QString>>  sample_wells;    //样本孔位列表
};

struct HuiFuData{
    QString deviceID;  //设备ID
    QString shiyanID; //实验ID
    QString cycle_number;   //循环数
    QList<QHash<QString,QString>>  sample_wells;    //样本孔位列表
};

class InstructionsService : public QObject
{
    Q_OBJECT
public:
    SocketClient *m_socketClient;

    QString path;
    SqliteDriver * sqlD;
    QVector<QStringList> yingguangData;
    QVector<QStringList> shiYanYingguangData;
    QList<YingGuang> yingGuangDataList;
    QList<HuiFuData> shiyanHuiFuList;
    QStringList ziJianData;
    QStringList kuoZengData;
    QStringList yangBenData;
    QStringList wenDuData;
    QStringList guZhangData;

    QStringList weiHuData;
    QString ipData;

    Convertion cov;

    InstructionsService();
    ~InstructionsService();

    void sendChecking(QString id);
    bool establishConnection(QString ipAddress, int port);
    bool dbFileDetect();
    bool configFileDetect();

    void saveYingGuangData();
    QList<YingGuang> getYingGuangData();

    void saveShiYanHuiFuData();
    QList<HuiFuData> getShiYanHuiFuData();

    void sendYingguangData(QString deviceID, QString shiyanID);
    void sendShiYanHuiFu(QString deviceID, QString shiyanID);

    void sendKuozengData(QString shiyanID, QString content);
    QStringList getKuoZengData();

    void sendYangbenData(QString shiyanID, QString content);
    QStringList getYangbenData();

    void sendWenduData(QString deviceID, QString shiyanID);
    QStringList getWenduData();

    void sendGuzhangData(QString deviceID, QString shiyanID);
    QStringList getGuZhangData();


    QString getIpData();
    QStringList getWeiHuData();


    void sendStop(QString deviceID, QString shiyanID, QString wendu);

    void sendContinue(QString deviceID, QString shiyanID);

    void sendClose(QString deviceID, QString shiyanID);

    void sleep();





    /*
    加热维护
    */
    void sendWeihuJiaresi(QString zhanKongbi, QString cmd);
    void sendWeihuSensorwendu(QString wendu1, QString wendu2, QString cmd);
    void sendWeihuRaoluanfeng(QString zhanKongbi, QString cmd);
    void sendWeihuRaoluanfengshanKaiguan(QString Kaiguan, QString cmd);
    void sendWeihuPaifengfengshan(QString Kaiguan, QString cmd);
    void sendWeihuDuiliufengshan(QString Zhankongbi, QString cmd);
    void sendWeihuBiaozhunWendu(QString wendu, QString cmd);
    void sendWeihuReshiyuandian(QString tongdao, QString step, QString cmd);
//    void sendWeihuXuanzhuan(QString zhuansu, QString fangxiang, QString cmd);
    void sendWeihuKongweipiancha(QString haocaitype, QString kongwei, QString yuandianpiancha,
                                              QString pingjunpiancha, QString cmd);
    /*
    荧光检测维护
    */
    void sendWeihuTongdaoKaiguan(QString tongdao, QString kaiguan, QString cmd);
    void sendWeihuTongdaozhi(QString tongdao, QString Yingguangzhi, QString AD, QString cmd);
    void sendWeihuJifaqiangdu(QString tongdao,QString qiangdu, QString cmd);
    void sendWeihuYingguangzengyi(QString tongdao, QString zengyi, QString cmd);
    /*
    状态检测维护
    */
    void sendWeihuMensuo(QString pingbi, QString kaiguan, QString cmd);
    void sendWeihuBigai(QString pingbi, QString kaiguan, QString cmd);
    void sendWeihuMensuojiaozheng(QString zhankongbi, QString cmd);

    /*
    IP地址和端口发送
    */
    void sendIP(QString ip1, QString ip2, QString ip3, QString ip4, QString port);


private:
    int sleepTime = 2000; //设置默认休眠时间，用于等待回传数据

private slots:
    void dataZijianPacketReady(SocketPacket packet);
    void dataYingguangPacketReady(SocketPacket packet);
    void dataShiyanYingguangdataPacket(SocketPacket packet);
    void dataKuozengPacketReady(SocketPacket packet);
    void dataYangbenPacketReady(SocketPacket packet);
    void dataWenduPacketReady(SocketPacket packet);
    void dataWeihuPacketReady(SocketPacket socketData);
    void dataIPPacketReady(SocketPacket socketData);
};


#endif // INSTRUCTIONSSERVICE_H
